package com.mycjj.android.activity;

import java.util.Calendar;
import java.util.Map;

import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.InputType;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.mycjj.android.MyCjjApplication;
import com.mycjj.android.R;
import com.mycjj.android.adapter.ProviceCityAreaAdapter;
import com.mycjj.android.bean.BaseBean;
import com.mycjj.android.bean.CarInfoBaseBean;
import com.mycjj.android.bean.CarInfoBaseBean.CarInfo;
import com.mycjj.android.bean.InsuranceBaseBean.InsuranceBean;
import com.mycjj.android.bean.StoreBaseBean.Store;
import com.mycjj.android.bean.TreeElement;
import com.mycjj.android.db.CityAreaTable;
import com.mycjj.android.http.ProjectHttpRequestImpl;
import com.mycjj.android.http.ProjectHttpRequestInterface;
import com.mycjj.android.util.Preferences;
import com.mycjj.android.util.Utils;
import com.mycjj.android.widget.wheel.OnWheelScrollListener;
import com.mycjj.android.widget.wheel.WheelView;

public class CarInfoActivity extends BaseActivity implements
		android.view.View.OnClickListener {

	private static int CarState_Show = 1;// 显示
	private static int CarState_Add = 2;// 添加
	private static int CarState_Update = 3; // 更新；

	private int carState = 1;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_me_carinfo);
		carState = getIntent().getIntExtra("car_state", 1);
		getWindow().setSoftInputMode(
				WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
		init();
		initWheel1();
	}

	private ImageView mHeaderLeftImageview;
	private Button mHeaderRightButton;
	private TextView mHeaderTitleTextView;

	private void initHeader() {
		mHeaderLeftImageview = (ImageView) findViewById(R.id.header_left_button);
		mHeaderLeftImageview.setImageResource(R.drawable.back);
		mHeaderRightButton = (Button) findViewById(R.id.header_right_button);
		ViewGroup.LayoutParams params = (ViewGroup.LayoutParams) mHeaderRightButton
				.getLayoutParams();
		params.height = (int) (30 * MyCjjApplication.getInstance()
				.getDisplayDensity());
		params.width = (int) (30 * MyCjjApplication.getInstance()
				.getDisplayDensity());
		// mHeaderRightButton.setVisibility(View.GONE);
		mHeaderRightButton
				.setBackgroundResource(R.drawable.heard_menu_style_setting);
		mHeaderRightButton.setLayoutParams(params);
		mHeaderRightButton.setOnClickListener(this);
		mHeaderRightButton.setVisibility(View.INVISIBLE);
		
		mHeaderTitleTextView = (TextView) findViewById(R.id.header_title_textview);
		mHeaderTitleTextView.setText("车辆信息");
		mHeaderLeftImageview.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				CarInfoActivity.this.finish();
			}
		});
	}

	private void init() {

		initHeader();
		initView();
		initViewState();
		initData();
	}

	private LinearLayout ll_carinfo_1, ll_carinfo_2, ll_carinfo_3,
			ll_carinfo_4;
	private EditText et_carinfo_1, et_carinfo_chejia, et_carinfo_fadongji;

	private TextView tv_carinfo_1, tv_carinfo_1_1, tv_carinfo_2,
			tv_carinfo_2_1, tv_carinfo_3, tv_carinfo_3_1, tv_carinfo_4,
			tv_carinfo_4_1;
	private Button btn_save_car_info;
	private void initView() {
		ll_carinfo_1 = (LinearLayout) findViewById(R.id.ll_carinfo_1);
		ll_carinfo_2 = (LinearLayout) findViewById(R.id.ll_carinfo_2);
		ll_carinfo_3 = (LinearLayout) findViewById(R.id.ll_carinfo_3);
		ll_carinfo_4 = (LinearLayout) findViewById(R.id.ll_carinfo_4);

		et_carinfo_1 = (EditText) findViewById(R.id.et_carinfo_1);
		et_carinfo_chejia = (EditText) findViewById(R.id.et_carinfo_chejia);
		et_carinfo_fadongji = (EditText) findViewById(R.id.et_carinfo_fadongji);

		tv_carinfo_1 = (TextView) findViewById(R.id.tv_car_info_1);
		tv_carinfo_1_1 = (TextView) findViewById(R.id.tv_car_info_1_1);
		tv_carinfo_2 = (TextView) findViewById(R.id.tv_carinfo_2);
		tv_carinfo_2_1 = (TextView) findViewById(R.id.tv_carinfo_2_1);
		tv_carinfo_3 = (TextView) findViewById(R.id.tv_carinfo_3);
		tv_carinfo_3_1 = (TextView) findViewById(R.id.tv_carinfo_3_1);
		tv_carinfo_4 = (TextView) findViewById(R.id.tv_carinfo_4);
		tv_carinfo_4_1 = (TextView) findViewById(R.id.tv_carinfo_4_1);
		btn_save_car_info = (Button)findViewById(R.id.btn_save_car_info);
		btn_save_car_info.setOnClickListener(this);
	}

	private String carId;
	Store currentStore;
	InsuranceBean insuranceBean;

	@Override
	protected void onResume() {
		super.onResume();
		
		TreeElement element = dataManager.getElement();
		if (element != null) {
			tv_carinfo_1.setText(element.getTitle());
			tv_carinfo_1_1.setText("购车时间 : " + element.getBuyCarDate());
		}else{
			tv_carinfo_1.setText("请选择");
			tv_carinfo_1_1.setText("购车时间 : 暂无");
		}
		
		insuranceBean = dataManager.getCurrentInsuranceBean();
		if (insuranceBean != null) {
			tv_carinfo_3.setText(insuranceBean.getTitle());
			tv_carinfo_3_1.setText("电话:" + insuranceBean.getTel());
		}else{
			tv_carinfo_3.setText("请选择");
			tv_carinfo_3_1.setText("电话:  暂无");
		}
		
		currentStore = dataManager.getCurrentStore();
		if (currentStore == null) {
			tv_carinfo_2.setText("请选择");
			tv_carinfo_2_1.setText("电话: 暂无");
		} else {
			tv_carinfo_2.setText(currentStore.getStore_name());
			tv_carinfo_2_1.setText("电话: " + currentStore.getStore_tel());
		}
	}
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
		dataManager.setCurrentInsuranceBean(null);
		dataManager.setCurrentStore(null);
		dataManager.setElement(null);
	}

	private void initViewState() {
		if (carState == CarState_Show) {
			ll_carinfo_1.setOnClickListener(null);
			ll_carinfo_2.setOnClickListener(null);
			ll_carinfo_3.setOnClickListener(null);
			ll_carinfo_4.setOnClickListener(null);

			et_carinfo_1.setEnabled(false);
			et_carinfo_chejia.setEnabled(false);
			et_carinfo_fadongji.setEnabled(false);

		} else {
			ll_carinfo_1.setOnClickListener(new btnListener());
			ll_carinfo_2.setOnClickListener(new btnListener());
			ll_carinfo_3.setOnClickListener(new btnListener());
			ll_carinfo_4.setOnClickListener(new btnListener());

			et_carinfo_1.setEnabled(true);
			et_carinfo_chejia.setEnabled(true);
			et_carinfo_fadongji.setEnabled(true);
		}
		if (carState == CarState_Update) {
			carId = getIntent().getStringExtra("carId");
			Log.e("mark", "carId:" + carId);
			request = new ProjectHttpRequestImpl(this, true);
			RequestParams params = new RequestParams();
			params.put("car_id", carId);
			params.put("client_id", ProjectHttpRequestInterface.client_id_key);
			params.put("token",
					Preferences.getSharedPreferences(this, "user_token", ""));
			request.requestUserCarGetWithDoneHandler("", params,
					new AsyncHttpResponseHandler() {
						@Override
						public void onSuccess(String content) {
							CarInfoBaseBean baseBean = dataManager
									.getCarInfoBaseBean();
							if (baseBean != null) {
								if (baseBean.getCode() == 200) {
									CarInfo info = baseBean.getData();
									TreeElement element = new TreeElement();
									element.setBrandId(info.getBrand1_id());
									element.setBrandId1(info.getBrand2_id());
									element.setBrandId2(info.getBrand3_id());
									element.setBrandId3(info.getBrand4_id());
									element.setTitle(info.getCar_name());
									dataManager.setElement(element);

									tv_carinfo_1.setText(info.getCar_name());
									tv_carinfo_1_1.setText("购车时间 : "
											+ info.getBuy_date());
									
									String plateArea = "",carNum = "";
									String temp = info.getPlate_number();
									Log.e("mark", "temp:"+temp);
//									try{
//										String stemp = URLDecoder.decode(temp, "GBK");
//										
//									}catch(Exception e){
//										e.printStackTrace();
//									}
									
									if(!TextUtils.isEmpty(temp) && temp.length() >= 4){
										plateArea = temp.substring(0,2);
										carNum = temp.substring(3,temp.length());
									}
									
									tv_plate_area.setText(plateArea);
									et_carinfo_1.setText(carNum);
									tv_carinfo_2.setText(info.getStore_name());
									tv_carinfo_2_1.setText("电话: "
											+ info.getStore_tel());

									tv_carinfo_3.setText(info
											.getApplicant_name());
									tv_carinfo_3_1.setText("投保日期:"
											+ info.getApplicant_date());
									tv_carinfo_4.setText(info
											.getYearly_check_date());

									et_carinfo_chejia.setText(info
											.getChassis_number());
									et_carinfo_fadongji.setText(info
											.getEngine_number());
								} else {
									Toast.makeText(
											CarInfoActivity.this,
											
													 baseBean.getMsg(),
											Toast.LENGTH_SHORT).show();
								}
							}
						}
					});
		}
	}

	static final int DATE_DIALOG_ID = 1;
	private int mYear;
	private int mMonth;
	private int mDay;

	private void initData() {
		final Calendar c = Calendar.getInstance();
		mYear = c.get(Calendar.YEAR);
		mMonth = c.get(Calendar.MONTH);
		mDay = c.get(Calendar.DAY_OF_MONTH);
		tv_carinfo_4.setText(mYear + "-" + Utils.pad(mMonth + 1) + "-"
				+ Utils.pad(mDay));
	}

	@Override
	protected Dialog onCreateDialog(int id) {
		switch (id) {
		case DATE_DIALOG_ID:
			DatePickerDialog picker = new DatePickerDialog(this,
					mDateSetListener, mYear, mMonth, mDay);
			picker.setTitle("请选择年审时间");
			return picker;
		}
		return null;
	}

	private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() {

		public void onDateSet(DatePicker view, int year, int monthOfYear,
				int dayOfMonth) {
			mYear = year;
			mMonth = monthOfYear;
			mDay = dayOfMonth;
			Log.e("mark", "year:" + year + ";monthOfYear:" + monthOfYear
					+ ";dayOfMonth:" + dayOfMonth);
			tv_carinfo_4.setText(year + "-" + Utils.pad(monthOfYear + 1) + "-"
					+ Utils.pad(dayOfMonth));
		}
	};

	public class btnListener implements OnClickListener {
		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.ll_carinfo_1:// 座驾选择界面
			{
				Intent intent = new Intent(CarInfoActivity.this,
						BrandActivity.class);
				startActivity(intent);
			}
				// getSelectCarModle();
				break;
			case R.id.ll_carinfo_2:// 4s 店
				Intent intent = new Intent(CarInfoActivity.this,
						SelectStoreActivity.class);
				intent.putExtra("action", 0);
				startActivity(intent);
				break;
			case R.id.ll_carinfo_3:// 保险
				Intent mIntent = new Intent(CarInfoActivity.this,
						InsuranceActivity.class);
				startActivity(mIntent);
				break;
			case R.id.ll_carinfo_4:// 年审时间
				showDialog(DATE_DIALOG_ID);
				break;
			default:
				break;
			}
		}
	}

	// private void getSelectCarModle() {
	//
	// request = new ProjectHttpRequestImpl(this, true);
	// RequestParams params = new RequestParams();
	// String storeid = Preferences.getSharedPreferences(this, "storeId", "");
	// params.put("store_id", storeid);
	// params.put("client_id", ProjectHttpRequestInterface.client_id_key);
	// params.put("token",
	// Preferences.getSharedPreferences(this, "user_token", ""));
	// request.requestStoreGetStoreCarWithDoneHandler("", params,
	// new AsyncHttpResponseHandler() {
	// @Override
	// public void onSuccess(String content) {
	// StoreCarBrandBaseBean baseBean = ProjectDataManage
	// .getInstance().getStoreCarBrandBaseBean();
	// if (baseBean != null) {
	// if (baseBean.getCode() == 200) {
	// List<StoreCarBrandBean> storeCarBrandBeanList = baseBean
	// .getData();
	// StoreCarBrandBean storeCarBrandBean = null;
	// StoreCarBrand storeCarBrand = null;
	// StoreCar storeCar = null;
	// List<StoreCarBrand> storeCarBrandList = null;
	// List<StoreCar> storeCarList = null;
	// ArrayList<TreeElement> treeElements = new ArrayList<TreeElement>();
	// TreeElement element = null;
	// // 第一级目录
	// for (int i = 0; i < storeCarBrandBeanList
	// .size(); i++) {
	// String id = (i + 1) + "";
	// storeCarBrandBean = storeCarBrandBeanList
	// .get(i);
	// String brandId = storeCarBrandBean
	// .getBrand_id();// 品牌
	// String brandName = storeCarBrandBean
	// .getBrand_name();
	// storeCarBrandList = storeCarBrandBean
	// .getBrand_next();
	// if (storeCarBrandList != null
	// && storeCarBrandList.size() > 0) {
	// // 第二级目录
	// for (int j = 0; j < storeCarBrandList
	// .size(); j++) {
	// String parentId1 = id;
	// String id1 = id + "" + (j + 1);
	// storeCarBrand = storeCarBrandList
	// .get(j);
	// String brandId1 = storeCarBrand
	// .getBrand_id();// 车系
	// String brandName1 = storeCarBrand
	// .getBrand_name();
	// storeCarList = storeCarBrand
	// .getBrand_next();
	// if (storeCarList != null
	// && storeCarList.size() > 0) {
	// // 第三级目录
	// for (int k = 0; k < storeCarList
	// .size(); k++) {
	// String id2 = (i + 1) + ""
	// + (j + 1) + ""
	// + (k + 1);
	// String parentId2 = id1;
	// storeCar = storeCarList
	// .get(k);
	// String brandId2 = storeCar
	// .getBrand_id();// 车型
	// String brandName2 = storeCar
	// .getBrand_name();
	// element = getThirdElement(
	// element, brandName2);
	// element.setId(id2);
	// element.setParentId(parentId2);
	// element.setBrandId(brandId);// 品牌
	// element.setBrandId1(brandId1);// 车系
	// element.setBrandId2(brandId2);// 车型
	// Log.d("mark",
	// "add three TreeElement: "
	// + element
	// .toString());
	// treeElements.add(element);
	// }
	// }
	// element = getTwoElement(element,
	// brandName1);
	// element.setId(id1);
	// element.setParentId(parentId1);
	// Log.d("mark",
	// "add two TreeElement: "
	// + element
	// .toString());
	// treeElements.add(element);
	// }
	// }
	// element = getOneElement(element, brandName);
	// element.setId(id);
	// Log.d("mark", "add one TreeElement: "
	// + element.toString());
	// treeElements.add(element);
	// }
	// Intent intent = new Intent(
	// CarInfoActivity.this,
	// CarBrandActivity.class);
	// // intent.putExtra("type", arg);
	// intent.putExtra("treeElements", treeElements);
	// startActivity(intent);
	// } else {
	// Toast.makeText(
	// CarInfoActivity.this,
	// "code:" + baseBean.getCode()
	// + ";message:"
	// + baseBean.getMsg(),
	// Toast.LENGTH_SHORT).show();
	// }
	// }
	// }
	// });
	// }
	//
	// private TreeElement getThirdElement(TreeElement element, String
	// brandName2) {
	// element = new TreeElement();
	// element.setLevel(3);
	// element.setTitle(brandName2);
	// element.setFold(false);// 未展开
	// element.setHasChild(false);
	// element.setHasParent(true);
	// return element;
	// }
	//
	// private TreeElement getTwoElement(TreeElement element, String brandName1)
	// {
	// element = new TreeElement();
	// element.setLevel(2);
	// element.setTitle(brandName1);
	// element.setFold(false);// 未展开
	// element.setHasChild(true);
	// element.setHasParent(true);
	// return element;
	// }
	//
	// private TreeElement getOneElement(TreeElement element, String brandName)
	// {
	// element = new TreeElement();
	// element.setLevel(1);
	// element.setTitle(brandName);
	// element.setFold(false);// 未展开
	// element.setHasChild(true);
	// element.setHasParent(false);
	// element.setParentId("null");
	// return element;
	//
	// }

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.header_right_button:
//			save();
			break;
		case R.id.btn_save_car_info:
			btn_save_car_info.setEnabled(false);
			save();
			break;
		}
	}

	private void save() {

		String palteArea = tv_plate_area.getText().toString().trim();
		if (TextUtils.isEmpty(palteArea) || "请选择".equals(palteArea)) {
			Toast.makeText(this, "请选择车牌地区！", Toast.LENGTH_SHORT).show();
			return;
		}

		String carNum = et_carinfo_1.getText().toString().trim();
		if (TextUtils.isEmpty(carNum)) {
			Toast.makeText(this, "车牌不能为空!", Toast.LENGTH_SHORT).show();
			return;
		}else if(carNum.length() > 5){
			Toast.makeText(this, "车牌号最多输入5位!", Toast.LENGTH_SHORT).show();
			return;
		}

		String carFrameNum = et_carinfo_chejia.getText().toString().trim();
		if (TextUtils.isEmpty(carFrameNum)) {
			Toast.makeText(this, "车架号不能为空!", Toast.LENGTH_SHORT).show();
			return;
		}
		
		

		String carEngineNum = et_carinfo_fadongji.getText().toString().trim();
		if (TextUtils.isEmpty(carEngineNum)) {
			Toast.makeText(this, "发动机编号不能为空!", Toast.LENGTH_SHORT).show();
			return;
		}

		TreeElement element = dataManager.getElement();
		if (element == null) {
			Toast.makeText(mApp, "请选择座驾!", Toast.LENGTH_SHORT).show();
			return;
		}
		request = new ProjectHttpRequestImpl(this, true);
		RequestParams params = new RequestParams();
		params.put("token",
				Preferences.getSharedPreferences(this, "user_token", ""));
		params.put("type", carState == 2 ? "bind" : "edit");
		if (carState == CarState_Update) {
			params.put("car_id", carId);
		}
		String storeId = Preferences.getSharedPreferences(mApp, "storeId", "");
		if (currentStore != null) {
			storeId = String.valueOf(currentStore.getStore_id());
		}
		params.put("store_id", storeId);
		params.put("brand1_id", element.getBrandId());
		params.put("brand2_id", element.getBrandId1());
		params.put("brand3_id", element.getBrandId2());
		params.put("brand4_id", element.getBrandId3());
		try {
			Log.e("mark", "palteArea:"+palteArea);
			Log.e("mark", "plate_number:"+carNum);
			params.put("plate_area", palteArea);
			params.put("plate_number", carNum);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		params.put("chassis_number", carFrameNum.trim());
		params.put("engine_number", carEngineNum.trim());
		params.put("regist_number", "");
		params.put("buy_date", Preferences.getSharedPreferences(mApp,
				"buyCarDate", "1990-01-01"));
		if (insuranceBean != null) {
			params.put("insurance_id", insuranceBean.getId());
			params.put("applicant_date", Preferences.getSharedPreferences(mApp,
					"applicant_date", "1990-01-01"));
		}
		params.put("city_code_id", String.valueOf(cityId1));
		params.put("client_id", ProjectHttpRequestInterface.client_id_key);
		request.requestUserCarBindCarWithDoneHandler("", params,
				new AsyncHttpResponseHandler() {
					@Override
					public void onSuccess(String content) {
						btn_save_car_info.setEnabled(true);
						BaseBean<?> baseBean = dataManager.getBaseBean();
						if (baseBean.getCode() == 200) {
							Toast.makeText(CarInfoActivity.this,
									(carState == 2 ? "添加" : "更新") + "成功!",
									Toast.LENGTH_SHORT).show();
							CarInfoActivity.this.finish();
						} else {
							Toast.makeText(
									CarInfoActivity.this,
									"code:" + baseBean.getCode() + ";message:"
											+ baseBean.getMsg(),
									Toast.LENGTH_SHORT).show();
						}
					}
					
					
					@Override
					public void onFailure(Throwable error, String content) {
						btn_save_car_info.setEnabled(true);
						Toast.makeText(CarInfoActivity.this,"error message:"+ content,Toast.LENGTH_SHORT).show();
						error.printStackTrace();
					}
				});
	}

	private Map<String, Integer> provinceMap1;
	private Map<String, Integer> cityMap1;

	private String[] provinceArray1;
	private String[] cityArray1;
	private String[] areaArray1;

	private WheelView provinceWheelView1;
	private WheelView cityWheelView1;
	private WheelView areaWheelView1;

	private ProviceCityAreaAdapter provinceAdapter1;
	private ProviceCityAreaAdapter cityAdapter1;
	private ProviceCityAreaAdapter areaAdapter1;
	private String areaId1;
	private int cityId1;
	private String provinceId1;
	private View mLl_plate_area;
	private TextView tv_plate_area;

	private void initWheel1() {
		mLl_plate_area = findViewById(R.id.ll_plate_area);
		tv_plate_area = (TextView) findViewById(R.id.tv_plate_area);
		tv_plate_area.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (mLl_plate_area.getVisibility() == View.VISIBLE) {
					mLl_plate_area.setVisibility(View.GONE);
				} else {
					mLl_plate_area.setVisibility(View.VISIBLE);
				}

			}
		});
		Button btn_cancel1 = (Button) findViewById(R.id.btn_cancel1);
		btn_cancel1.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				mLl_plate_area.setVisibility(View.GONE);
			}
		});

		Button btn_sure1 = (Button) findViewById(R.id.btn_sure1);
		btn_sure1.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				StringBuilder sb = new StringBuilder();
				sb.append(provinceArray1[provinceWheelView1.getCurrentItem()]);
				sb.append(areaArray1[areaWheelView1.getCurrentItem()]);

				tv_plate_area.setText(sb.toString());
				areaId1 = areaArray1[areaWheelView1.getCurrentItem()];
				cityId1 = cityMap1.get(cityArray1[cityWheelView1
						.getCurrentItem()]);
				provinceId1 = provinceArray1[provinceWheelView1
						.getCurrentItem()];
				Log.d("mark", "areaId1:" + areaId1 + ";cityId1：" + cityId1
						+ ";provinceId1:" + provinceId1);
				mLl_plate_area.setVisibility(View.GONE);
			}
		});

		provinceWheelView1 = (WheelView) findViewById(R.id.provice_1);
		cityWheelView1 = (WheelView) findViewById(R.id.city_1);
		areaWheelView1 = (WheelView) findViewById(R.id.area_1);

		// 初始化省滚轮列表选择器
		initProviceMap1();
		provinceAdapter1 = new ProviceCityAreaAdapter(this, provinceArray1, 0);
		provinceWheelView1.setViewAdapter(provinceAdapter1);
		provinceWheelView1.setCurrentItem(0);
		provinceWheelView1.addScrollingListener(privinceScrollListener1);

		// 初始化城市滚轮列表选择器
		String provinceName = "";
		try {
			provinceName = provinceArray1[0];	
		} catch (Exception e) {
			e.printStackTrace();
		}
//		int cityId = provinceMap1.get(provinceName);
		initCityMap1(provinceName);

		cityAdapter1 = new ProviceCityAreaAdapter(this, cityArray1, 0);
		cityWheelView1.setViewAdapter(cityAdapter1);
		cityWheelView1.setCurrentItem(0);
		cityWheelView1.addScrollingListener(cityScrollListener1);

		// 初始化地区滚轮列表选择器
		String cityName = "";
		try {
			cityName = cityArray1[0];	
		} catch (Exception e) {
			// TODO: handle exception
		}
		
		int areaId = cityMap1.get(cityName);

		initAreaMap1(areaId);
		areaAdapter1 = new ProviceCityAreaAdapter(this, areaArray1, 0);
		areaWheelView1.setViewAdapter(areaAdapter1);
		areaWheelView1.setCurrentItem(0);
	}

	OnWheelScrollListener privinceScrollListener1 = new OnWheelScrollListener() {

		@Override
		public void onScrollingStarted(WheelView wheel) {
		}

		@Override
		public void onScrollingFinished(WheelView wheel) {
			int currentItem = wheel.getCurrentItem();
			String provinceName = provinceArray1[currentItem];
			initCityMap1(provinceName);
			cityAdapter1 = new ProviceCityAreaAdapter(CarInfoActivity.this,
					cityArray1, 0);
			cityWheelView1.setViewAdapter(cityAdapter1);
			cityWheelView1.setCurrentItem(0);

			String cityName = cityArray1[0];
			int cityId = cityMap1.get(cityName);
			initAreaMap1(cityId);
			areaAdapter1 = new ProviceCityAreaAdapter(CarInfoActivity.this,
					areaArray1, 0);
			areaWheelView1.setViewAdapter(areaAdapter1);
			areaWheelView1.setCurrentItem(0);
		}
	};

	OnWheelScrollListener cityScrollListener1 = new OnWheelScrollListener() {

		@Override
		public void onScrollingStarted(WheelView wheel) {
		}

		@Override
		public void onScrollingFinished(WheelView wheel) {
			int areaId = cityMap1.get(cityArray1[wheel.getCurrentItem()]);
			initAreaMap1(areaId);
			areaAdapter1 = new ProviceCityAreaAdapter(CarInfoActivity.this,
					areaArray1, 0);
			areaWheelView1.setViewAdapter(areaAdapter1);
			areaWheelView1.setCurrentItem(0);
		}
	};

	public void initProviceMap1() {
		provinceMap1 = CityAreaTable.getPlatProvince();
		provinceArray1 = provinceMap1.keySet().toArray(
				new String[provinceMap1.size()]);
	}

	public void initCityMap1(String attr) {
		cityMap1 = CityAreaTable.getPlateCity(attr);
		cityArray1 = cityMap1.keySet().toArray(new String[cityMap1.size()]);
	}

	public void initAreaMap1(int cityId) {
		// areaArray1 = areaMap1.keySet().toArray(new String[areaMap.size()]);
		areaArray1 = getResources().getStringArray(R.array.string_array);
	}

}
